<?php

/**
* LocalizationModule.class.php
*
* Display selected localization and all avaliable localizations
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once("HTML/Template/IT.php");
require_once("framework/PageModule.class.php");
require_once("framework/LocalizationSingleton.class.php");


// {{{ LocalizationModule

class LocalizationModule extends PageModule 
{
    // {{{ Class operations 

    // {{{ LocalizationModule
    /**
    * C'tor
    */
    function LocalizationModule()
    {
        trigger_error("ENTER LocalizationModule::LocalizationModule()", E_USER_NOTICE);
    }
    // }}}
    // {{{ getContent

    /**
    * Function returns page content
    *
    */

    function getContent()
    {

        trigger_error("ENTER LocalizationModule::getContent()", E_USER_NOTICE);
        
        $tpl = new HTML_Template_IT("./templates");
        $tpl->loadTemplatefile("localization.tpl.xhtml",true,true);

        $currentLocale = LocalizationSingleton::instance()->getLocale();
        $avaliableLocale = LocalizationSingleton::instance()->getAvaliableLocale();
        
        
        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');

        $counter = 0 ;
        $queryString = "";
        
        foreach( $avaliableLocale as $locale )
        {
    
            if( $locale == $currentLocale)
            {
                $tpl->setCurrentBlock("static") ;    
                $tpl->setVariable("TITLE", $locale) ;
                $tpl->parseCurrentBlock() ;
            }    
            else
            {
                $tpl->setCurrentBlock("link") ;    
                $tpl->setVariable("TITLE", $locale) ;

                foreach( $_GET as $key => $value )
                {   
                    if ( $key != "locale" )
                    {
                        $queryString .= $key."=".$value."&";
                    }
                }

                $tpl->setVariable("LINK", $global['service_url']."?".$queryString."locale=".$locale) ;
                $tpl->parseCurrentBlock() ;
            }

            if ( $counter < count( $avaliableLocale ) - 1 )
            {
                $tpl->setCurrentBlock("separator") ;    
                $tpl->setVariable("ON","") ;
                $tpl->parseCurrentBlock() ;
            }

            $tpl->parse('localization');
            $counter++;
        }
        
        trigger_error("LEAVE LocalizationModule::getContent()", E_USER_NOTICE);
        return $tpl->get(); 

    }
    
    // }}}

    // }}}
}

// }}} 

?>
